home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / tk / tkinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  3.6 KB  |  115 lines

  1. /* Midnight Commander Tk Information display
  2.    Copyright (C) 1995 Miguel de Icaza
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <config.h>
  19. #include <string.h>
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "fs.h"
  23. #include "dlg.h"
  24. #include "widget.h"
  25. #include "info.h"
  26. #include "tkmain.h"
  27.  
  28. /* The following three include files are needed for cpanel */
  29. #include "main.h"
  30. #include "dir.h"
  31. #include "panel.h"
  32.  
  33. /* Create the Tk widget */
  34. void x_create_info (Dlg_head *h, widget_data parent, WInfo *info)
  35. {
  36.     char *cmd;
  37.     widget_data container = info->widget.wcontainer;
  38.  
  39.     cmd = tk_new_command  (container, info, 0, 'o');
  40.     tk_evalf ("newinfo %s %s " VERSION, (char *)container,
  41.           wtk_win (info->widget));
  42. }
  43.  
  44. /* Updates the information on the Tk widgets */
  45. void x_show_info (WInfo *info, struct my_statfs *s, struct stat *b)
  46. {
  47.     char bsize [17];
  48.     char avail_buf [17], total_buf [17];
  49.     char *mod, *acc, *cre;
  50.     char *fname;
  51.     int  have_space, have_nodes;
  52.     int  space_percent;
  53.     int  ispace_percent;
  54.  
  55.     fname = cpanel->dir.list [cpanel->selected].fname;
  56.     sprint_bytesize (bsize, b->st_size, 0);
  57.     mod = strdup (file_date (b->st_mtime));
  58.     acc = strdup (file_date (b->st_atime));
  59.     cre = strdup (file_date (b->st_ctime));
  60.  
  61.     /* Do we have information on space/inodes? */
  62.     have_space = s->avail > 0 || s->total > 0;
  63.     have_nodes = s->nfree > 0 || s->nodes > 0;
  64.  
  65.     /* Compute file system usage */
  66.     sprint_bytesize (avail_buf, s->avail, 1);
  67.     sprint_bytesize (total_buf, s->total);
  68.     space_percent = s->total
  69.     ? 100 * s->avail / s->total : 0;
  70.  
  71.     /* inode percentage use */
  72.     ispace_percent = s->total ? 100 * s->nfree / s->nodes : 0;
  73.     
  74.     tk_evalf ("info_update %s.b {%s} %X %X " /* window fname dev ino */
  75.           "{%s} %o "            /* mode mode_oct */
  76.           "%d %s %s "               /* links owner group */
  77. #ifdef HAVE_ST_BLOCKS
  78. #define BLOCKS b->st_blocks
  79.           "1 %d "                    /* have_blocks blocks */
  80. #else
  81. #define BLOCKS 0
  82.           "0 %d "                   /* have_blocks blocks */
  83. #endif
  84.               "{%s} "                     /* size */
  85. #ifdef HAVE_RDEV
  86. #define RDEV b->st_rdev
  87.           "1 %d %d "                /* have_rdev rdev rdev2 */
  88. #else
  89. #define RDEV 0
  90.           "0 %d %d "                /* have_rdev rdev rdev2 */
  91. #endif
  92.           "{%s} {%s} {%s} "         /* create modify access */
  93.           "{%s} {%s} {%s} "         /* fsys dev type */
  94.           "%d {%s} %d {%s} "        /* have_space avail percent total */
  95.           "%d %d %d %d",            /* have_ino nfree inoperc inotot */
  96.  
  97.           wtk_win (info->widget), fname,
  98.           b->st_dev, b->st_ino,
  99.           string_perm (b->st_mode), b->st_mode & 07777,
  100.           b->st_nlink, get_owner (b->st_uid), get_group (b->st_gid),
  101.           BLOCKS,
  102.           bsize,
  103.           RDEV >> 8, RDEV & 0xff,
  104.           cre, mod, acc,
  105.           s->mpoint, s->device, s->typename,
  106.           have_space, avail_buf, space_percent, total_buf,
  107.           have_nodes, s->nfree, ispace_percent, s->nodes);
  108.  
  109.     free (mod);
  110.     free (acc);
  111.     free (cre);
  112. }
  113.  
  114.  
  115.